﻿using liaowa2.Interface.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using liaowa2.Entity.DTO.Article;
using liaowa2.Utils;
using liaowa2.Entity.Web;
using liaowa2.Dao.Web;

namespace liaowa2.Impl.Manager
{
    public class ArticleImpl : IArticleInterface
    {
        ArticleDao dao;
        public ArticleImpl(ArticleDao articleDao)
        {
            this.dao = articleDao;
        }

        public bool Delete(int id)
        {
            return this.dao.Update(new Entity.DO.Article() { Id = id, Status = 1 });
        }

        public EntityPage<ListOutputDTO> List(ListInputDTO input)
        {
            int count = 0;
            int offset = UtilsBase.GetListOffsetNumber(input.CurrentIndex, input.PageSize);
            EntityPage<ListOutputDTO> entityPage = new EntityPage<ListOutputDTO>();
            entityPage.Items = this.dao.List(offset, input.PageSize, input.StartDate, input.EndDate, input.Categoty, input.KeyWord, out count).ToList();
            entityPage.Count = count;
            return entityPage;
        }

        public bool Off(int id)
        {
            return this.dao.Update(new Entity.DO.Article() { Id = id, Status = 2 });
        }
    }
}
